package mysql

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Mobile    string `gorm:"type:varchar(20);not null"`
	Password  string `gorm:"type:char(32);not null"`
	HeadImage string `gorm:"type:varchar(500);not null"`
	NickName  string `gorm:"type:varchar(30);not null"`
	Address   string `gorm:"type:varchar(100);not null"`
	Age       int64  `gorm:"type:int(11);not null"`
	Qq        string `gorm:"type:varchar(30);not null"`
	Email     string `gorm:"type:varchar(50);not null"`
}

func (u *User) FindUserByPhone(db *gorm.DB, mobile string) error {
	return db.Debug().Where("mobile=?", mobile).Find(u).Error
}

func (u *User) UserAdd(db *gorm.DB) error {
	return db.Debug().Create(u).Error
}

func (u *User) FindUserByUserId(db *gorm.DB, id int64) error {
	return db.Debug().Where("id=?", id).First(u).Error
}

func (u *User) UserUpdate(db *gorm.DB) error {
	return db.Debug().Updates(u).Error

}
